﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PermissionBase.Core.Domain;
using PermissionBase.Core.Service;

public partial class Admin_Modules_StaffMgr_StaffInfo : System.Web.UI.Page
{
    private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Admin_Modules_StaffMgr_StaffInfo));

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Cache.SetCacheability(HttpCacheability.NoCache);

        try
        {
            //填充下拉框。
            FillSelects();

            if (Request.QueryString["mode"] == "new")
            {
                divTitleMess.InnerText = "新增职员";
            }
            else if (Request.QueryString["mode"] == "edit")
            {
                divTitleMess.InnerText = "编辑职员";

                string id = Request.QueryString["id"];
                if (id != null)
                {
                    Staff s = CommonSrv.LoadObjectById(typeof(Staff), id) as Staff;

                    txtStaffLoginId.Value = s.LoginId;
                    txtStaffName.Value = s.Name;
                    cbStaffDisabled.Checked = (s.FlagUse == 0);//maudyi 0 正常使用；-1 停止使用。
                    txtStaffOrderId.Value = s.EmpBaseId.ToString();
                    
                    txtStaffCode.Value = s.SystemCode;
                    
                    if (s.CompCode != null && s.CompCode.Length > 0)
                    {
                        ListItem liCountry = selectStaffCountry.Items.FindByValue(s.CompCode);
                        if (liCountry != null) liCountry.Selected = true;
                    }
                    
                }
            }
        }
        catch (Exception ex)
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "error", "<script type=\"text/javascript\">error=true;</script>");
            log.Error(null, ex);
        }
    }

    #region private void FillSelects()
    private void FillSelects()
    {
        //如果数据字典里面没有任何一项，就提示未设定
        //国家。
        SysCodeType sctCountry = SysCodeTypeSrv.GetSysCodeTypeByTag("countrys");
        if (sctCountry == null)
        {
            selectStaffCountry.Items.Add(new ListItem("数据字典中未设定", "-1"));
        }
        else
        {
            selectStaffCountry.Items.Add(new ListItem("", "-1"));
            foreach (SysCode sc in sctCountry.SysCodes)
            {
                selectStaffCountry.Items.Add(new ListItem(sc.Name, sc.Tag));
            }
        }

        //民族。
        SysCodeType sctNation = SysCodeTypeSrv.GetSysCodeTypeByTag("MZ");
        if (sctNation == null)
        {
            selectStaffNation.Items.Add(new ListItem("数据字典中未设定", "-1"));
        }
        else
        {
            selectStaffNation.Items.Add(new ListItem("", "-1"));
            foreach (SysCode sc in sctNation.SysCodes)
            {
                selectStaffNation.Items.Add(new ListItem(sc.Name, sc.Tag));
            }
        }

        //职位。
        SysCodeType sctPosition = SysCodeTypeSrv.GetSysCodeTypeByTag("ZW");
        if (sctPosition == null)
        {
            selectStaffPosition.Items.Add(new ListItem("数据字典中未设定", "-1"));
        }
        else
        {
            selectStaffPosition.Items.Add(new ListItem("", "-1"));
            foreach (SysCode sc in sctPosition.SysCodes)
            {
                selectStaffPosition.Items.Add(new ListItem(sc.Name, sc.Tag));
            }
        }

        //职称。
        SysCodeType sctTitle = SysCodeTypeSrv.GetSysCodeTypeByTag("ZC");
        if (sctTitle == null)
        {
            selectStaffTitle.Items.Add(new ListItem("数据字典中未设定", "-1"));
        }
        else
        {
            selectStaffTitle.Items.Add(new ListItem("", "-1"));
            foreach (SysCode sc in sctTitle.SysCodes)
            {
                selectStaffTitle.Items.Add(new ListItem(sc.Name, sc.Tag));
            }
        }

        //政治面貌。
        SysCodeType sctPolitical = SysCodeTypeSrv.GetSysCodeTypeByTag("ZZMM");
        if (sctPolitical == null)
        {
            selectStaffPolitical.Items.Add(new ListItem("数据字典中未设定", "-1"));
        }
        else
        {
            selectStaffPolitical.Items.Add(new ListItem("", "-1"));
            foreach (SysCode sc in sctPolitical.SysCodes)
            {
                selectStaffPolitical.Items.Add(new ListItem(sc.Name, sc.Tag));
            }
        }

        //最高学历。
        SysCodeType sctDegree = SysCodeTypeSrv.GetSysCodeTypeByTag("WHCD");
        if (sctDegree == null)
        {
            selectStaffDegree.Items.Add(new ListItem("数据字典中未设定", "-1"));
        }
        else
        {
            selectStaffDegree.Items.Add(new ListItem("", "-1"));
            foreach (SysCode sc in sctDegree.SysCodes)
            {
                selectStaffDegree.Items.Add(new ListItem(sc.Name, sc.Tag));
            }
        }

        //性别。
        selectStaffSex.Items.Add(new ListItem("", "-1"));
        selectStaffSex.Items.Add(new ListItem("男", "0"));
        selectStaffSex.Items.Add(new ListItem("女", "1"));

        //婚否。
        selectStaffMarried.Items.Add(new ListItem("", "-1"));
        selectStaffMarried.Items.Add(new ListItem("未婚", "0"));
        selectStaffMarried.Items.Add(new ListItem("已婚", "1"));
    }
    #endregion

}
